package com.hyopt.modules.app.controller;

import com.hyopt.modules.mqtt.Callback;
import com.hyopt.modules.mqtt.MQTTConnect;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName GateSimulationDemo
 * @Description TODO
 * @Author lijie
 * @Date 2023/4/12 14:21 星期三
 * @Version 1.0
 */
@RestController
@EnableScheduling
@RequestMapping("/api/gate")
@Api(value="ApiChatGPTController",tags={"智能回复机器人"})
@Slf4j
public class GateSimulationDemo {

    @Autowired
    MQTTConnect mqttConnect;
    public static String basicData = "{\"gatew\":\"LS05\",\"gateidc\":2541,\"time\":";
    public static String basicData2 = ",VW400\":2500,\"VW410\":3000,\"VW420\":0,\"VW430\":0,\"VW440\":0,\"VW450\":0,\"VW402\":2,\"VW412\":1,\"VW422\":0,\"VW432\":0,\"VW442\":0,\"VW404\":6,\"VW414\":3,\"VW424\":0,\"VW434\":0,\"VW444\":0,\"VW406\":2,\"VW416\":1,\"VW426\":0,\"VW436\":0,\"VW446\":0,\"VW408\":1,\"VW418\":0,\"VW428\":0,\"VW438\":0,\"VW448\":0,\"VW320\":25,\"VW382\":3,\"VW384\":1,\"VW386\":1,\"VW390\":0,\"VW394\":0,\"M18.0\":0,\"M18.1\":0,\"M18.2\":0,\"M18.3\":0,\"M18.4\":0,\"M18.5\":0,\"M18.6\":0,\"M18.7\":0,\"VW2001\":2048,\"VW2002\":2100,\"VW2003\":13320,\"VW2004\":2048,\"VW2005\":7,\"VW2006\":2010,\"VW2007\":55808,\"VW2008\":0,\"VW2009\":0,\"VW2010\":1,\"VW2011\":256,\"VW2012\":57,\"VW2013\":14592,\"VW2014\":0,\"VW2015\":0,\"VW2016\":0,\"VW2017\":0,\"VW2018\":0,\"VW2019\":0,\"VW2020\":0,\"VW324\":8000}";
    public static int sendCount = 5000;

    /**
     * 仿真mqtt网关demo发送
     */
    @GetMapping("/simulation")
//    @Scheduled(cron = "0/5 * * * * ? ")
    public String simulation() {
        try {
        mqttConnect.setMqttClient("", "",new Callback());
            for (int i = 0; i < sendCount; i++) {
                Thread.sleep(50);
                Long time = System.currentTimeMillis();
                mqttConnect.pub("/Li9527", basicData + time);
                log.info("发送成功，时间戳----,{}",time);
            }
        } catch (MqttException | InterruptedException e) {
            e.printStackTrace();
        }
        return "发送结束";
    }


}
